package com.atguigu.crud.dao;

import com.atguigu.crud.bean.Employee;
import com.atguigu.crud.bean.EmployeeExample;
import java.util.List;

import org.apache.ibatis.annotations.*;

public interface EmployeeMapper {
    @Select(" select count(*) from tbl_emp")
    long countByExample(EmployeeExample example);

    int deleteByExample(EmployeeExample example);
    @Delete("delete from tbl_emp where emp_id=#{emp_id}")
    int deleteByPrimaryKey(Integer empId);

    int insert(Employee record);
    @Insert(" insert into tbl_emp (emp_id, emp_name,gender, email, d_id) values(#{empId},#{empName},#{gender},#{email},#{dId})")
    int insertSelective(Employee record);

    @Select(" select * from tbl_emp left join tbl_dept on tbl_emp.d_id=tbl_dept.dept_id  where emp_id = #{empId}")
    List<Employee> selectByExample(Employee employee);

    @Select(" select * from tbl_emp  where emp_id = #{empId}")
    Employee selectByPrimaryKey(Integer empId);

    @Select(" select * from tbl_emp")
    List<Employee>  select();

    @Select("select emp_id, emp_name, gender, email,tbl_dept.dept_name from tbl_emp left join tbl_dept on tbl_emp.d_id=tbl_dept.dept_id")
    List<Employee> selectByExampleWithDept(EmployeeExample example);

    @Select(" select  emp_id, emp_name, gender, email, d_id,dept_id,dept_name from tbl_emp left join tbl_dept on tbl_emp.d_id=tbl_dept.dept_id  where emp_id = #{empId}")
     Employee selectByPrimaryKeyWithDept(Integer empId);

    int updateByExampleSelective(@Param("record") Employee record, @Param("example") EmployeeExample example);

    int updateByExample(@Param("record") Employee record, @Param("example") EmployeeExample example);

    @Update("update tbl_emp set emp_name = #{empName},gender = #{gender},email = #{email} " +
   "  d_id = #{dId} where emp_id = #{empId}")
    Employee updateByPrimaryKeySelective(Integer empId);

    @Update("update tbl_emp set emp_name = #{empName},gender = #{gender},email = #{email} " +
            "  d_id = #{dId} where emp_id = #{empId}")
    Employee updateByPrimaryKey(Integer empId);
}